﻿package frEngine.loaders.particleSub.multyEmmiterType
{
    import __AS3__.vec.*;
    import flash.geom.*;
    import frEngine.animateControler.particleControler.*;
    import frEngine.math.*;

    public class LinearMultyEmmiter extends Object implements IMultyEmmiterType
    {
        private var _defaultStartPos:Vector3D;
        private var _defaultEndPos:Vector3D;
        private var _defaultMultyPlaySpeed:int = 0;
        public var openAngle:Number;
        private var speedVector3d:Vector3D;
        private var _distanceBirthNum:int = 1;
        private var strValue:String;
        private var params0:Number = 0;
        private var params1:Number = 0;
        private var params2:Number = 0;
        private var params3:Number = 0;
        private static const qu:Quaternion = new Quaternion();
        private static const _temp:Vector3D = new Vector3D();

        public function LinearMultyEmmiter(param1:String)
        {
            this._defaultStartPos = new Vector3D();
            this._defaultEndPos = this.defaultStartPos;
            this.strValue = param1;
            return;
        }// end function

        public function get defaultStartPos() : Vector3D
        {
            return this._defaultStartPos;
        }// end function

        public function get defaultEndPos() : Vector3D
        {
            return this._defaultEndPos;
        }// end function

        public function get defaultMultyPlaySpeed() : int
        {
            return this._defaultMultyPlaySpeed;
        }// end function

        public function initData(param1:ParticleParams) : void
        {
            var _loc_2:* = this.strValue.split(",");
            var _loc_3:* = _loc_2[1];
            var _loc_4:* = _loc_3.split(" ");
            this._defaultStartPos = new Vector3D(_loc_4[0], _loc_4[1], _loc_4[2]);
            _loc_3 = _loc_2[2];
            _loc_4 = _loc_3.split(" ");
            this._defaultEndPos = new Vector3D(_loc_4[0], _loc_4[1], _loc_4[2]);
            this.openAngle = Number(_loc_2[3]);
            this.calculateDistanceBirthNum(param1);
            return;
        }// end function

        private function calculateDistanceBirthNum(param1:ParticleParams) : void
        {
            var _loc_2:Vector3D = null;
            var _loc_3:Number = NaN;
            var _loc_4:int = 0;
            var _loc_5:Number = NaN;
            var _loc_6:Number = NaN;
            var _loc_7:Number = NaN;
            var _loc_8:Number = NaN;
            if (param1.distanceBirth)
            {
                _loc_2 = this.defaultEndPos.subtract(this._defaultStartPos);
                _loc_3 = _loc_2.length;
                _loc_4 = _loc_3 / this.defaultMultyPlaySpeed;
                _loc_5 = param1.emitterTimeEffectPeriod;
                _loc_6 = 1 / _loc_4;
                _loc_7 = _loc_5 * _loc_6;
                if (_loc_7 > 1)
                {
                    this._distanceBirthNum = Math.ceil(_loc_3 / param1.birthDistance);
                }
                else
                {
                    _loc_8 = _loc_3 * _loc_7;
                    this._distanceBirthNum = Math.ceil(_loc_8 / param1.birthDistance);
                }
            }
            else
            {
                this._distanceBirthNum = 1;
            }
            return;
        }// end function

        public function get distanceBirthNum() : int
        {
            return this._distanceBirthNum;
        }// end function

        public function reInit(param1:Vector3D, param2:Vector3D, param3:int, param4:ParticleParams, param5:Vector.<Number>) : void
        {
            var _loc_12:Number = NaN;
            if (param3 < 1)
            {
                param3 = this._defaultMultyPlaySpeed;
            }
            if (param1 == null)
            {
                param1 = this._defaultStartPos;
            }
            if (param2 == null)
            {
                param2 = this._defaultEndPos;
            }
            var _loc_6:* = param2.subtract(param1);
            var _loc_7:* = _loc_6.crossProduct(Vector3D.Y_AXIS);
            var _loc_8:* = _loc_7.crossProduct(_loc_6);
            _loc_8.normalize();
            qu.fromAxisAngle(_loc_8, this.openAngle / 180 * Math.PI);
            qu.rotatePoint(_loc_6, _temp);
            param2 = param1.add(_temp);
            this.speedVector3d = param2.subtract(param1);
            var _loc_9:* = this.speedVector3d.normalize();
            var _loc_10:* = _loc_9 / param3;
            var _loc_11:* = 1 / _loc_10;
            if (param4.distanceBirth)
            {
                this.params0 = param4.birthDistance / _loc_9;
                _loc_12 = Math.min(param4.emitterTimeEffectPeriod, _loc_10);
                this.params1 = _loc_12 / this._distanceBirthNum;
                this.params2 = this._distanceBirthNum;
            }
            else if (param4.tailEnabled)
            {
                this.params0 = _loc_11;
                this.params1 = param4.tailMaxDistance / _loc_9;
            }
            else
            {
                this.params0 = _loc_11;
            }
            this.params3 = _loc_9;
            param5.push(this.params0, this.params1, this.params2, this.params3);
            param5.push(param1.x, param1.y, param1.z, 0);
            param5.push(this.speedVector3d.x, this.speedVector3d.y, this.speedVector3d.z, 0);
            return;
        }// end function

    }
}
